function lst = subsasgn(lst, S, varargin)
%SUBSASGN Implements the subscripted assignment for sllist
%
% [ Syntax ]
%   - lst{i} = e
%   - lst{i1, i2, ...} = deal(e1, e2, ...)
%   - lst(indices) = src
% 
% [ Description ]
%   - lst(i) = e assigns e to the element in lst indexed by i
%   
%   - lst{i1, i2, ...} = deal(e1, e2, ...) assigns multiple elements in 
%     the list.
%
%   - lst(indices) = src assigns a subset of elements from the source.
%     src can be another sllist or a cell array.
%
% [ History ]
%   - Created by Dahua Lin, on Jan 5, 2008
%

switch S(1).type
    case '{}'
        lst = subsasgn(lst.items, S, varargin{:});
    case '()'
        if length(S.subs) > 1
            error('sltoolbox:sllist:invalidsubs', ...
                'Only one-dimensional subscript-accessing is supported for sllist.');
        end
        
        src = varargin{1};
        if iscell(src)
            lst.items = subsasgn(lst.items, S, src);     
        elseif isempty(src)
            lst = remove_at(lst, S.subs{1});
        else
            lst.items = subsasgn(lst.items, S, cell(src));
        end
    case '.'
        error('sltoolbox:sllist:invalidsubs', ...
            'dot-indexing is not supported for sllist');     
end